
//g++ -O2 test.cpp http_transmit.o -L x86_64-redhat-linux/ -lcurl -lssl -lcrypto -std=c++11
//x86_64-linux-musl-g++ -static -O2 test.cpp http_transmit.o -L /home/zx/libs/x86_64-linux-musl/ -lcurl -lssl -lcrypto -std=c++11
//aarch64-linux-gnu-g++ -O2 test.cpp http_transmit.o -L /home/zx/libs/aarch64-linux-gnu/ -lcurl -lssl -lcrypto -ldl -lpthread -std=c++11

//sudo dnf --enablerepo=crb install glibc-static libstdc++-static
#include <string>
#ifdef _MSC_VER
#include <windows.h>
#include <locale.h>
#pragma comment(lib, "Crypt32.lib")
#pragma comment(lib, "ws2_32.lib")
#endif

#include "task_thread_pool.hpp"

task_thread_pool::task_thread_pool pool{8};

extern "C" int http_transmit(const char* url, const char* json, char* r, int* rlen);

std::string url  = "http://192.168.1.188:38000/esim/operateResult/esimImeiCheck";
std::string body = R"({"imei": "861927050017377"})";

int main(int argc, char** argv)
{
    (void)argc;
    (void)argv;
#ifdef _MSC_VER
    setlocale(LC_ALL, ".utf8");
    SetConsoleCP(CP_UTF8);
    SetConsoleOutputCP(CP_UTF8);
#endif   // _MSC_VER

    long total = 1;

    for(int i = 0; i<total; i++)
    {
        auto a = pool.submit([&](int idx) {
            char r[1024];
            int  rlen = sizeof(r);

            int result = http_transmit(url.c_str(), body.c_str(), r, &rlen);
            if (rlen > 0 && (result == 200 || result == 204))
                printf("%d, [%d] %s\n", idx, result, r);
            else
                printf("%d, [%d]\n", idx, result);
        }, i);
    }
    pool.wait_for_tasks();
    
    return 0;
}
